/*
Autor: Alexander Savochkin, 2010
New BSD License
*/

#include "Response.h"

#include <boost/lexical_cast.hpp>

using boost::lexical_cast;

namespace SRCLF {

	const char* Response::str_access_denied_code = "1";
	const char* Response::str_captured_code = "2";
	const char* Response::str_unknown_channel_code = "3";
	const char* Response::str_command_parse_error_code = "4";

	void Response::onGetInput(string& result,double input_value)
	{
		string str_value = lexical_cast<string>(input_value);
		result = "ok\n" + str_value;
	}

	void Response::onGetOutput(string& result,double output_value)
	{
		string str_value = lexical_cast<string>(output_value);
		result = "ok\n" + str_value;
	}

	void Response::onSetOutput(string& result)
	{
		result = "ok\n";
	}

	void Response::onDisable(string& result)
	{
		result = "ok\n";
	}

	void Response::onKeep(string& result,double keep_value)
	{
		string str_value = lexical_cast<string>(keep_value);
		result = "ok\n" + str_value;
	}

	void Response::onControlCaptured(string& result)
	{
		result = "ok\n";
	}

	void Response::onControlReleased(string& result)
	{
		result = "ok\n";
	}

	void Response::onAccessDenied(string& result)
	{
		result = string("error\n") + str_access_denied_code + "\naccess denied";
	}

	void Response::onOtherClientCapturedControl(string& result)
	{
		result = string("error\n")+str_captured_code+"\nalready captured";
	}

	void Response::onUnknownChannelName(string& result, const string& channel_name)
	{
		result = string("error\n")+ str_unknown_channel_code +"\nunrecognized channel name: "+channel_name;
	}

	void Response::onCommandParseError(string& result)
	{
		result = string("error\n")+ str_command_parse_error_code +"Can't parse command.";
	}

} //namespace SRCLF
